package com.zrrd;

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int m = scanner.nextInt();
        int k = scanner.nextInt();
        boolean[][] grid = new boolean[n][m];

        for (int i = 0; i < k; i++) {
            String command = scanner.next();
            int x = scanner.nextInt() - 1;
            int y = scanner.nextInt() - 1;

            switch (command) {
                case "c":
                    grid[x][y] = true;
                    break;
                case "l":
                    int lResult = -1;
                    for (int j = y - 1; j >= 0; j--) {
                        if (!grid[x][j]) {
                            lResult = j + 1;
                            break;
                        }
                    }
                    System.out.println(lResult == -1 ? -1 : (x + 1) + " " + lResult);
                    break;
                case "r":
                    int rResult = -1;
                    for (int j = y + 1; j < m; j++) {
                        if (!grid[x][j]) {
                            rResult = j + 1;
                            break;
                        }
                    }
                    System.out.println(rResult == -1 ? -1 : (x + 1) + " " + rResult);
                    break;
                case "u":
                    int uResult = -1;
                    for (int j = x - 1; j >= 0; j--) {
                        if (!grid[j][y]) {
                            uResult = j + 1;
                            break;
                        }
                    }
                    System.out.println(uResult == -1 ? -1 : uResult + " " + (y + 1));
                    break;
                case "d":
                    int dResult = -1;
                    for (int j = x + 1; j < n; j++) {
                        if (!grid[j][y]) {
                            dResult = j + 1;
                            break;
                        }
                    }
                    System.out.println(dResult == -1 ? -1 : dResult + " " + (y + 1));
                    break;
            }
        }
        scanner.close();
    }
}